package com.dfbz.demo;

import java.util.concurrent.locks.LockSupport;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo03_wait计时等待 {
    public static void main(String[] args) throws Exception {
        new Thread() {
            @Override
            public void run() {
                synchronized (Object.class) {
                    for (int i = 0; i < 1000; i++) {
                        System.out.println("南昌拌粉");
                        try {
                            // 等待1000ms后将自动醒来,同时也会释放锁
                            Object.class.wait(1000);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }.start();

        new Thread() {
            @Override
            public void run() {
                synchronized (Object.class) {
                    for (int i = 0; i < 1000; i++) {
                        System.out.println("抚州泡粉");
                    }
                }
            }
        }.start();
    }
}
